package cn.wolfcode.shop.producer;

import cn.wolfcode.shop.vo.CreateOrderVo;
import com.alibaba.fastjson.JSON;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;
import java.util.HashMap;
import java.util.Map;

@Component
public class CreateOrderInfoProducer {
    @Autowired
    private JmsTemplate jmsTemplate;
    //确定消息发送地点
    Destination destination = new ActiveMQQueue("shop.order");

    /**
     * 发送创建订单消息的方法
     */
    public void sendMessage(Long userId, CreateOrderVo createOrderVo){
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("userId", userId);
        param.put("createOrderVo", JSON.toJSONString(createOrderVo));
        //使用JMS模板类发送消息
        jmsTemplate.convertAndSend(destination, param);
    }
}
